/**
 * @author wangxiaowei
 * 公共组查询
 */
var sort = null;
var grid = null;
function initdutylist(){
 Ext.BLANK_IMAGE_URL=Ext.get('basePath').getValue()+"ajaxFramework/ext-2.1/resources/images/default/s.gif";	
var colModel = new Ext.grid.ColumnModel([
		{header:'组名称',dataIndex:'groupName',menuDisabled : true},		
		{header:'状态',dataIndex:'start',menuDisabled : true},
		{header:'序号',dataIndex:'orderNo',menuDisabled : true},
		{header:'操作',dataIndex:'operate',menuDisabled : true,renderer:function(s,m,rec){
		if(rec.data.start == '禁用'){
		return "<a  href="+"javascript:enableAllGroup('"+rec.data.id+"')>启用</a>  <a  href="+"javascript:updateToDuty('"+rec.data.id+"')>修改</a>";
		}else{
		return "<a  href="+"javascript:enableAllGroup('"+rec.data.id+"')>禁用</a>   <a  href="+"javascript:updateToDuty('"+rec.data.id+"')>修改</a>";
		}
		}},
		{header:'id',dataIndex:'id',hidden:true}
	]);
	var url = Ext.get('url').getValue();
	sort = new Ext.data.JsonStore({
		url:url,
		fields:['groupName','state','orderNo','id','start'],
		root:'root',
		totalProperty:'totalProperty'
	});
	var bbar = new Ext.PagingToolbar({
		pageSize:15,
		store:sort,
		displayInfo:true,
		emptyMsg:'没有记录'
	});
	
	 grid = new Ext.grid.GridPanel({
		title:'公共组列表',
		cm:colModel,
		renderTo:'topic-grid',
		store:sort,
		loadMask:true,
		autoHeight:true,
		tbar:[{
			 text: '添加',
             iconCls: 'silk-add',
              handler:function(){
             	window.location.href=Ext.get('basePath').getValue()+'tjsinfo/tjsoa/system/addAllGroupForm.do';
             }
		}],
		bbar:bbar,
		viewConfig:{
			forceFit:true,
			enableRowBody:true,
			getRowClass:function(record,rowIndex,p,ds){
				if(record.get('start') == '禁用')
				{
					return 'red-row';
				}
			}
		}
	});
	sort.load({params:{start:0, limit: 15}});	
}


/**
	 * 禁用一个用户
	 * @param {} id 用户ID
	 */
function enableAllGroup(id){
	 Ext.MessageBox.show({
          title:'消息',
          msg: '是否执行此操作?',
          buttons: Ext.MessageBox.YESNO,
          fn: function(btn){
          	  if(btn == 'yes'){
          	  	    var url = Ext.get('urlenable').getValue();
				Ext.Ajax.request({
					url:url,
					params:{
						id:id
					},
					success:function(response, options){
						    var responseArray = Ext.util.JSON.decode(response.responseText);                                              
		                     if(responseArray.success==true){
		                        Ext.Msg.alert('信息','操作成功！',function(){
		                        		sort.reload({callback :function(){
			                        		grid.getView().refresh();	
			                        	}});
		                        });     
		                     }
		                    else{
		                    	Ext.Msg.alert('信息','操作失败！');     
		                    } 
					}
				});
				
          	  }	
          },
          icon: Ext.MessageBox.QUESTION
      });		
}

function updateToDuty(id,first){
	 window.location.href=Ext.get('basePath').getValue()+'tjsinfo/tjsoa/system/updateAllGroupForm.do?id='+id;	
}
	
	